from tortoise import BaseDBAsyncClient


async def upgrade(db: BaseDBAsyncClient) -> str:
    return """
        CREATE TABLE IF NOT EXISTS `contest` (
    `contest_id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT
) CHARACTER SET utf8mb4;
CREATE TABLE IF NOT EXISTS `problem` (
    `problem_id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `content` VARCHAR(255) NOT NULL
) CHARACTER SET utf8mb4;
CREATE TABLE IF NOT EXISTS `rounds` (
    `id` BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `round_id` INT NOT NULL,
    `contest_id` INT NOT NULL,
    UNIQUE KEY `uid_rounds_round_i_c68478` (`round_id`, `contest_id`),
    CONSTRAINT `fk_rounds_contest_55cbc0cd` FOREIGN KEY (`contest_id`) REFERENCES `contest` (`contest_id`) ON DELETE CASCADE
) CHARACTER SET utf8mb4;
CREATE TABLE IF NOT EXISTS `team` (
    `team_id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT
) CHARACTER SET utf8mb4;
CREATE TABLE IF NOT EXISTS `roundteam` (
    `id` BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `position` INT NOT NULL,
    `round_id` BIGINT NOT NULL,
    `team_id` INT NOT NULL,
    UNIQUE KEY `uid_roundteam_round_i_18db1f` (`round_id`, `team_id`),
    CONSTRAINT `fk_roundtea_rounds_64ed0e24` FOREIGN KEY (`round_id`) REFERENCES `rounds` (`id`) ON DELETE CASCADE,
    CONSTRAINT `fk_roundtea_team_3bc7345b` FOREIGN KEY (`team_id`) REFERENCES `team` (`team_id`) ON DELETE CASCADE
) CHARACTER SET utf8mb4;
CREATE TABLE IF NOT EXISTS `score` (
    `id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `score` JSON NOT NULL,
    `team_id` BIGINT NOT NULL,
    CONSTRAINT `fk_score_roundtea_e939dd8b` FOREIGN KEY (`team_id`) REFERENCES `roundteam` (`id`) ON DELETE CASCADE
) CHARACTER SET utf8mb4;
CREATE TABLE IF NOT EXISTS `aerich` (
    `id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `version` VARCHAR(255) NOT NULL,
    `app` VARCHAR(100) NOT NULL,
    `content` JSON NOT NULL
) CHARACTER SET utf8mb4;"""


async def downgrade(db: BaseDBAsyncClient) -> str:
    return """
        """
